package com.fanjun.learning.net.http;

import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by memedai on 2016/11/21.
 */
public class HttpClientTest {

    public static void main(String[] args) throws IOException {
        HttpPost httpPost = new HttpPost("http://api.yilelink.com/?r=api/send_sms/inform");
        String message = "api_key=611d71ba2666dd59e68ce51b2c2e96c2&api_secret=d926de68d9a3872e9308f5f31aa2cfa5&type=inform&mobile=15195809814&message=亲爱的范军，您有100件待办事项将在2016-11-24后过期，请抓紧办理，谢谢！";
        try {
            CloseableHttpClient client = HttpClients.createDefault();
//            List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
            List<String> params = new ArrayList<String>();
//            params.add(new BasicNameValuePair("message", message));
            params.add(message);
//            HttpEntity httpEntity = new UrlEncodedFormEntity(params, "UTF-8");
            HttpEntity httpEntity1 = new StringEntity(message,"UTF-8");
            httpPost.setEntity(httpEntity1);
            CloseableHttpResponse response = client.execute(httpPost);
            System.out.println(EntityUtils.toString(response.getEntity()));
            ConcurrentMap concurrentMap = new ConcurrentHashMap();
        } finally {
            httpPost.releaseConnection();
        }

    }
}
